package com.my.auth.service;

import com.my.auth.entity.MyClient;
import com.my.auth.exception.LoadClientsException;
import com.my.auth.security.IClientDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zhaodongchao
 * @date 2020/3/21 19:52
 **/
@Slf4j
@Service
public class MyClientDetailsServiceImpl implements IClientDetailsService {

    @Override
    public MyClient loadClientByClientId(String clientId) throws LoadClientsException {
        log.info(clientId);
        Map<String, Object> additionalInformation = new ConcurrentHashMap<>(2);
        additionalInformation.put("website","https://www.baidu.com");
        additionalInformation.put("appName","爱妹子");
        return MyClient.builder()
                       .clientId("policy_100")
                       .clientSecret("123")
                       .authorizedGrantTypes(new LinkedHashSet<>(Arrays.asList("authorization_code","password","refresh_token")))
                       .accessTokenValiditySeconds(1800)
                       .refreshTokenValiditySeconds(1800)
                       .scope(new LinkedHashSet<>(Arrays.asList("read","write")))
                       .additionalInformation(additionalInformation)
                       .build();
    }
}
